package com.easemob.chat;

import com.easemob.util.EMLog;
import com.xonami.javaBells.JinglePacketHandler;
import com.xonami.javaBells.JingleSession;
import java.util.HashMap;
import net.java.sip.communicator.impl.protocol.jabber.extensions.jingle.JingleAction;
import net.java.sip.communicator.impl.protocol.jabber.extensions.jingle.JingleIQ;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.XMPPError;

class EMSessionHandler extends JinglePacketHandler
{
  protected EMVoiceCallSession activeSession = null;
  private static final String TAG = EMSessionHandler.class.getSimpleName();

  public void processPacket(Packet paramPacket)
  {
    JingleIQ localJingleIQ = (JingleIQ)paramPacket;
    if (localJingleIQ.getType() == IQ.Type.ERROR)
    {
      EMLog.e(TAG, "error is received with error code = " + localJingleIQ.getError().getCode());
      if ((localJingleIQ.getError().getCode() == 503) && (this.activeSession != null))
      {
        this.activeSession.changeState(EMCallStateChangeListener.CallState.DISCONNNECTED, EMCallStateChangeListener.CallError.ERROR_INAVAILABLE);
        this.activeSession.closeSession(null);
      }
      return;
    }
    if (isGeneralJiq(localJingleIQ))
    {
      super.processPacket(paramPacket);
      return;
    }
    JingleSession localJingleSession = (JingleSession)this.jingleSessions.get(localJingleIQ.getSID());
    if (jiqAccepted(localJingleIQ))
    {
      EMVoiceCallSession localEMVoiceCallSession;
      if (localJingleIQ.getAction() == JingleAction.CALL_ACCEPT)
      {
        if (localJingleSession == null)
          return;
        localEMVoiceCallSession = (EMVoiceCallSession)localJingleSession;
        localEMVoiceCallSession.handleCallAccept(localJingleIQ);
      }
      else if (localJingleIQ.getAction() == JingleAction.CALLER_RELAY)
      {
        if (localJingleSession == null)
          return;
        localEMVoiceCallSession = (EMVoiceCallSession)localJingleSession;
        localEMVoiceCallSession.handleCallerRelay(localJingleIQ);
      }
      else
      {
        super.processPacket(paramPacket);
      }
    }
  }

  EMVoiceCallSession getActiveSession()
  {
    return this.activeSession;
  }

  void setActiveSession(EMVoiceCallSession paramEMVoiceCallSession)
  {
    this.activeSession = paramEMVoiceCallSession;
  }

  EMSessionHandler(XMPPConnection paramXMPPConnection)
  {
    super(paramXMPPConnection);
  }

  protected boolean isGeneralJiq(JingleIQ paramJingleIQ)
  {
    JingleAction localJingleAction = paramJingleIQ.getAction();
    return (localJingleAction == JingleAction.CONTENT_ADD) || (localJingleAction == JingleAction.CONTENT_MODIFY) || (localJingleAction == JingleAction.CONTENT_ACCEPT) || (localJingleAction == JingleAction.CONTENT_REJECT) || (localJingleAction == JingleAction.CONTENT_REMOVE) || (localJingleAction == JingleAction.DESCRIPTION_INFO) || (localJingleAction == JingleAction.SECURITY_INFO) || (localJingleAction == JingleAction.SESSION_INFO) || (localJingleAction == JingleAction.SESSION_TERMINATE);
  }

  protected boolean jiqAccepted(JingleIQ paramJingleIQ)
  {
    return false;
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     com.easemob.chat.EMSessionHandler
 * JD-Core Version:    0.6.1
 */